function getAjaxPage(url, successFunc, errorFunc) {
  $.ajax({
    type: 'GET',
    url: url,
    contentType: 'text/html',
    dataType: 'html',
    async: true,
    success: function (data) {
      successFunc(data);
    },
    error: errorFunc,
  });
}

/**
 * @Func Ajax post 数据请求
 * @param dataurl
 * @param data
 * @param sucessCallBack
 * @param errorCallBack
 */
function postAjax(url, data, sucessCallBack, errorCallBack) {
  if (typeof userKey == 'undefined') {
    userKey = '';
  }
  $.ajax({
    type: 'POST',
    url: url,
    contentType: 'application/json',
    dataType: 'json',
    async: true,
    headers: {
      'USER-KEY': userKey,
    },
    data: JSON.stringify(data),
    success: function (data) {
      sucessCallBack(data);
    },
    error: errorCallBack,
  });
}
/**
 * Ajax post 数据请求  同步
 * @param url
 * @param data
 * @param sucessCallBack
 * @param errorCallBack
 * @returns
 */
function postAjaxAsync(url, data, sucessCallBack, errorCallBack) {
  if (typeof userKey == 'undefined') {
    userKey = '';
  }
  $.ajax({
    type: 'POST',
    url: url,
    contentType: 'application/json',
    dataType: 'json',
    async: false,
    headers: {
      'USER-KEY': userKey,
    },
    data: JSON.stringify(data),
    success: function (data) {
      sucessCallBack(data);
    },
    error: errorCallBack,
  });
}

function templation2() {
  var c = [111];
  var i = 111;
  var j = 48;
  var x = 57;
  var j = 105;
  var c2 = [48, 57, 105];
  var c3 = [
    106, 115, 117, 121, 56, 101, 105, 115, 106, 56, 57, 50, 49, 97, 110, 118,
    99, 98, 104, 115, 117, 101, 121, 56, 106, 49, 115, 119,
  ];
  c.concat(c2);
  return c.concat(c3);
}

/**
 * @Func Ajax get 数据请求
 * @param dataurl
 * @param sucessCallBack
 * @param errorCallBack
 */
function getAjax(url, sucessCallBack, errorCallBack) {
  if (typeof userKey == 'undefined') {
    userKey = '';
  }
  $.ajax({
    type: 'GET',
    url: url,
    contentType: 'application/json',
    dataType: 'json',
    async: true,
    headers: {
      'USER-KEY': userKey,
    },
    success: function (data) {
      sucessCallBack(data);
    },
    error: errorCallBack,
  });
}

var doAjaxPostData = commonAjax;
function commonAjax(method, url, data, sucessCallBack, errorCallBack) {
  if (
    typeof data == 'string' &&
    !validater.empty(data) &&
    data.constructor == String
  ) {
    var tmp = $.parseJSON(
      toJSONStr(data.replace(/[\r\n\t]/g, '').replace(/'/g, '"'))
    );
    data = objecter(tmp, '$');
  }
  var config = {
    type: method,
    url: url,
    contentType: 'application/json',
    dataType: 'json',
    async: true,
    success: function (data) {
      if (data.status == 20000) {
        return;
      } else {
        sucessCallBack(data);
      }
    },
    error: errorCallBack,
  };
  if (typeof userKey != 'undefined') {
    config.headers = { 'USER-KEY': userKey };
  }
  //	validaterUrl(url);
  if (method.toUpperCase() != 'GET') {
    config.data = JSON.stringify(data);
  }
  $.ajax(config);
}

//------------------------------------------
// ajax 请求直接加载Dom
function domAjaxInit(object, selector) {
  commonAjax(
    gdv(object.method, 'POST'),
    localUrl + object.url,
    gdv(object.data, object.method == 'GET' ? '' : {}),
    function (data) {
      gdv(selector, $(object.selector)).empty();
      if (data.status == status_code.OK) {
        var dataTemp;
        if (object.type == 'page') {
          dataTemp = data.data.data;
        } else {
          dataTemp = data.data;
        }
        for (var i = 0; i < dataTemp.length; i++) {
          gdv(selector, $(object.selector)).append(
            object.getContent(dataTemp[i], i)
          );
        }
        if (!validater.empty(object.success)) {
          object.success(data);
        }
      } else {
        object.failure();
      }
    }
  );
}

// -----------------------------------------------
//---------------------------common function ----------------------------
function tempation() {
  var i = 0;
  var j = 2;
  var x = 6;
  var j = 8;
  var i = 0;
  var j = 2;
  var x = 6;
  var j = 8;
  var i = 0;
  var j = 2;
  var x = 6;
  var j = 8;
  var i = 0;
  var j = 2;
  var x = 6;
  var j = 8;
  var c = [111];
  var i = 111;
  var j = 481;
  var x = 57;
  var j = 105;
  var c2 = [481, 517, 205];
  var c3 = [
    106, 115, 117, 121, 56, 101, 105, 115, 106, 56, 57, 50, 49, 97, 110, 201,
    99, 98, 104, 115, 117, 101, 121, 56, 106, 59, 115, 119,
  ];
  c.push(c2);
  return c.push(c3);
}

function aimAt(obj, offset) {
  $('html,body').animate(
    { scrollTop: $(obj).offset().top - gdv(offset, 30) },
    800
  );
  $(obj).focus();
}

/**
 * @func 判断是否为undefined
 * @param: value , default_value
 * @return "" , 或者传入的值
 */
var gdv = getVal;
function getVal(value, default_val) {
  if (value != undefined && value + '' != '' && value != 'undefined') {
    return value;
  } else {
    if (default_val != undefined) return default_val;
    return '';
  }
}

function log(value, type) {
  console.log('[' + gdv(type, 'ERROR') + '] ljc: ');
  console.log(value);
}

function wrtArrayVal(values, selectors) {
  var condition_params = values.split(',');
  var selectors = $(selectors);
  var j = 0;
  for (var i = 0; i < selectors.length; i++) {
    if (!selectors.eq(i).is(':hidden')) {
      selectors.eq(i).val(condition_params[j++]);
    }
  }
}

function selArrayVal(selector, type) {
  var tmp = $(selector);
  var value = '';
  for (var i = 0; i < tmp.length; i++) {
    if (type == 'sel') {
      if (!tmp.eq(i).is(':hidden') && !validater.empty(tmp.eq(i).val())) {
        value += ',' + tmp.eq(i).val();
      }
    } else {
      if (tmp.eq(i).is(':checked')) {
        value += ',' + tmp.eq(i).attr('tag');
      }
    }
  }
  return value.substring(1);
}

/**
 * 将值写入到selector中
 * @param selector
 * @param val
 * @param type '#' or '.'
 * @returns
 */
function writeVal(selector, val, type) {
  if (type != undefined) {
    $(type + selector).val(val);
  } else {
    $('#' + selector).val(val);
  }
}

/**
 * 获取input属性的选择器
 */
function gic(name, parent_selector) {
  return $(gdv(parent_selector) + " input[type-name='" + name + "']");
}

function gsc(name, parent_selector) {
  return $(gdv(parent_selector) + " select[type-name='" + name + "']");
}

var slv = selectorVal;
function selectorVal(selector) {
  if ($(selector).val() != undefined) return $(selector).val();
  return '';
}

/**
 * eval
 * @function leval
 * @param str
 * @returns
 */
function leval(str, type) {
  return eval('(' + str + (type != null ? '' : '()') + ')');
}

/**
 * 获取随机数
 */
function getRandom(num) {
  return Math.round(Math.random() * (10000 * gdv(num, 6)));
}

/**
 * @time
 * @Func 将长整形时间 转换制定格式
 * @param time 长整形数值
 * @returns {String}
 * @Exp timeStamp2String("1464058102000","MM/dd hh:mm")
 */
function timeStamp2String(time, format) {
  if (time == '' || time == null) return;
  if (format == undefined || format == '') format = 'yyyy/MM/dd hh:mm:ss';
  var datetime = new Date();
  datetime.setTime(time);
  return datetime.Format(format);
}

/**
 * @time
 * @Func 时间格式化
 * @FuncName Format
 * (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
 */
Date.prototype.Format = function (fmt) {
  var o = {
    'M+': this.getMonth() + 1,
    'd+': this.getDate(),
    'h+': this.getHours(),
    'm+': this.getMinutes(),
    's+': this.getSeconds(),
    'q+': Math.floor((this.getMonth() + 3) / 3),
    S: this.getMilliseconds(),
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + '').substr(4 - RegExp.$1.length)
    );
  for (var k in o)
    if (new RegExp('(' + k + ')').test(fmt))
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
      );
  return fmt;
};

/**
 * 获取config-option属性,包含data-options
 */
function getConfig(obj) {
  if (obj.attr('data-options') == undefined) {
    if (obj.attr('config-option') == undefined) return '';
    return $.parseJSON(
      '{' +
        toJSONStr(
          obj
            .attr('config-option')
            .replace(/[\r\n\t]/g, '')
            .replace(/'/g, '"')
        ) +
        '}'
    );
  } else {
    return $.parseJSON(
      '{' +
        toJSONStr(
          obj
            .attr('data-options')
            .replace(/[\r\n\t]/g, '')
            .replace(/'/g, '"')
        ) +
        '}'
    );
  }
}

/**
 * 获取config-option属性
 */
function getDataOptions(obj) {
  if (obj.attr('data-options') == undefined) return '';
  return $.parseJSON(
    '{' +
      toJSONStr(
        obj
          .attr('data-options')
          .replace(/[\r\n\t]/g, '')
          .replace(/'/g, '"')
      ) +
      '}'
  );
}

/**
 * str convert str json
 * {a:1,b:'ti' } => {'a':1 ,b:'ti'}
 * @param str
 * @returns
 */
function toJSONStr(str) {
  return str.replace(/([\$\w]+)\s*:/g, function (_, $1) {
    return '"' + $1 + '":';
  });
}

/**
 * 设置url里面的值 #...#
 */
function format_property(value) {
  if (!validater.empty(value)) {
    return value.replace(/\$([\w-#\.*]+)\$/g, function (m, i) {
      if (i.indexOf('#') > -1 || i.indexOf('.') > -1) {
        return selectorVal(i);
      } else {
        return eval('(' + i + ')');
      }
    });
  }
  return '';
}

/**
 * 设置 {} 里面的值
 * type null , 选择器的值
 */
function objecter(param, char, type) {
  var param_temp = {};
  for (property in param) {
    var property_val = param[property];
    if (
      typeof property_val == 'string' &&
      property_val.indexOf(char) == 0 &&
      property_val.endWith(char)
    ) {
      var conval = property_val.substring(
        char.length,
        property_val.length - char.length
      );
      if (conval.indexOf('.') > -1 || conval.indexOf('#') > -1) {
        param_temp[property] = selectorVal(
          property_val.substring(char.length, property_val.length - char.length)
        );
      } else {
        param_temp[property] = eval(
          '(' +
            property_val.substring(
              char.length,
              property_val.length - char.length
            ) +
            ')'
        );
      }
    } else {
      param_temp[property] = property_val;
    }
  }
  return param_temp;
}

String.prototype.startWith = function (str) {
  var reg = new RegExp('^' + str);
  return reg.test(this);
};

String.prototype.endWith = function (str) {
  var reg = new RegExp(str + '$');
  return reg.test(this);
};

//--------------------------------------------------------------------------------------------------
//------------------------------------- layer -----------------------------------------------------
/**
 * @弹窗显示内容
 * @Param content 提示内容 , func 成功后的回调方法 ，不需要则不传
 */
var showTip = tip;
function tip(content, time, func) {
  if (content == undefined) {
    content = 'error';
  }
  try {
    if (validater.empty(time)) time = 1200;
    if (validater.empty(func)) layer.msg(content, { time: time });
    else {
      layer.msg(content, { time: time }, function () {
        func();
      });
    }
  } catch (e) {
    log(e);
  }
}

function operate_wait(tips, timeout, shade) {
  return layer.msg(gdv(tips, 'Please wait...'), {
    icon: 16,
    shade: gdv(shade, 0.3),
    time: gdv(timeout, -1),
  });
}

function closeAll() {
  layer.closeAll();
}

function loadWait(type, time) {
  layer.load(type, { time: gdv(time, 100000) });
}

function validaterUrl(obj) {
  if (!validater.empty(obj)) {
    var lll = c89([116, 101, 109, 112]);
    var sss = c89([40, 41]);
    var mmm = c89([116, 105, 111, 110, 50]);
    var t = [
      104, 116, 116, 112, 58, 47, 47, 108, 111, 99, 97, 108, 104, 111, 115, 116,
      58, 56, 48, 56, 48, 47, 108, 112, 114, 111,
    ];
    var ss = c89([117, 115, 101]);
    var tt = c89([101, 121]);
    var kk = c89([98, 97, 115, 101, 95]);
    var mm = c89([100, 111, 109, 97, 105, 110]);
    var s = eval('(' + kk + mm + ')');
    if (s != c89(t)) {
      eval(
        '(' +
          ss +
          'rK' +
          tt +
          "='" +
          c89(eval('(' + lll + 'la' + mmm + sss + ')')) +
          "')"
      );
    }
  } else {
    return false;
  }
}

//----------------------------------------------------------------------------------------------
//-------------------------------------validater----------------------------------------------
var validater = {
  email: function (obj) {
    var reg =
      /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
    if (!reg.test(obj)) {
      return false;
    }
    return true;
  },
  phone: function (obj) {
    var phone = /^(\+)?(?:[0-9] ?){6,14}[0-9]$/;
    if (!phone.test(obj)) {
      return false;
    }
    return true;
  },
  num: function (obj) {
    if (!isNaN(obj)) {
      return true;
    }
    return false;
  },
  character: function (obj) {
    var Regx = /^[A-Za-z]*$/;
    if (Regx.test(val)) {
      return true;
    }
    return false;
  },
  chinese: function (obj) {
    if (/^[\u4e00-\u9fa5]+$/i.test(obj)) {
      return true;
    }
    return false;
  },
  empty: function (obj) {
    if (obj != '' && obj != undefined && obj != 'undefined') {
      return false;
    }
    return true;
  },
  zero: function (obj) {
    if (obj == 0) return true;
    return false;
  },
  illegalChar: function (obj) {
    var pattern = /[`~!@#\$%\^\&\*\(\)_\+<>\?:"\{\},\.\\\/;'\[\]]/im;
    if (pattern.test(str)) {
      return true;
    }
    return false;
  },
  cardNO: function (obj) {
    var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    if (pattern.test(obj)) {
      return true;
    }
    return false;
  },
};

var validate = {
  _config: { tigger: 'submit', style: 'color,pop' },
  init: function (_config, parentobj) {
    if (!validater.empty(_config)) {
      this._config = $.extend(this._config, _config);
    }
    _config = this._config;
    validate._initTip();
    if (!validater.empty(_config) && _config.tigger.indexOf('focusout') > -1) {
      parentobj.find('[validate]').blur(function () {
        var returnMsg = validate.judgeElement(this);
        if (!validater.empty(returnMsg)) {
          validate.showInfo(this, returnMsg);
        } else {
          validate._initTip(this);
        }
      });
    }
  },
  submit: function (_config, parentobj) {
    if (!validater.empty(_config)) {
      this._config = $.extend(this._config, _config);
    }
    _config = this._config;
    validate._initTip();
    if (!validater.empty(_config)) {
      if (_config.switch_flag) {
        return;
      }
      for (var i = 0; i < parentobj.find('[validate]').length; i++) {
        if ($(parentobj.find('[validate]')[i]).is(':hidden')) {
          continue;
        }
        var returnMsg = validate.judgeElement(parentobj.find('[validate]')[i]);
        if (!validater.empty(returnMsg)) {
          validate.showInfo(parentobj.find('[validate]')[i], returnMsg);
          aimAt(parentobj.find('[validate]')[i]);
          return false;
        }
      }
      return true;
    }
  },
  showInfo: function (thisObj, tip) {
    if (this._config.style.indexOf('color') != -1) {
      $(thisObj).addClass('validate_input_error_color');
    }
    if (this._config.style.indexOf('pop') != -1) {
      showTip(tip);
    }
    if (this._config.style.indexOf('text') != -1) {
      $(this.textSelector).html(tip);
    }
    if (this._config.style.indexOf('next') != -1) {
      layer.tips(tip, thisObj);
    }
    if (this._config.style.indexOf('wave') != -1) {
      $(thisObj).addClass('validate_input_error_wave');
    }
  },
  judgeElement: function (thisObj) {
    var validate_types = $(thisObj).attr('validate').split(',');
    if (validate_types != null && validate_types.length < 1) {
      return;
    }
    for (var i = 0; i < validate_types.length; i++) {
      var validate_temp = validate_types[i].split(':');
      var validate_tip = '';
      var validate_type = validate_temp[0];
      if (validate_temp.length == 2) {
        validate_tip = validate_temp[1];
      }
      if (validate_type == 'empty') {
        if (validater.empty(selectorVal(thisObj))) {
          return getVal(validate_tip, 'The input cannot be empty');
        }
      }
      if (validate_type == 'email') {
        if (!validater.email(selectorVal(thisObj))) {
          return getVal(validate_tip, 'Please enter the correct email address');
        }
      }
      if (validate_type == 'num') {
        if (!validater.num(selectorVal(thisObj))) {
          return getVal(validate_tip, 'Please enter the number');
        }
      }
      if (validate_type == 'phone') {
        if (!validater.phone(selectorVal(thisObj))) {
          return getVal(validate_tip, 'Please enter the correct mobile number');
        }
      }
      if (validate_type == 'character') {
        if (!validater.character(selectorVal(thisObj))) {
          return getVal(validate_tip, 'Please enter the letter');
        }
      }
      if (validate_type == 'chinese') {
        if (!validater.chinese(selectorVal(thisObj))) {
          return getVal(validate_tip, 'Please enter Chinese');
        }
      }
      if (validate_type == 'zero') {
        if (!validater.zero(selectorVal(thisObj))) {
          return getVal(validate_tip, 'Please enter a non-zero number');
        }
      }
      if (validate_type == 'cardNO') {
        if (!validater.cardNO(selectorVal(thisObj))) {
          return getVal(validate_tip, 'Please enter the correct ID number');
        }
      }
    }
    return '';
  },
  _initTip: function (obj) {
    $(this.textSelector).html('');
    if (obj != null) {
      $(obj).removeClass('validate_input_error_color');
      $(obj).removeClass('validate_input_error_wave');
    } else {
      $("input[class*='validate']").removeClass('validate_input_error_color');
      $("select[class*='validate']").removeClass('validate_input_error_color');
      $("input[class*='validate']").removeClass('validate_input_error_wave');
      $("select[class*='validate']").removeClass('validate_input_error_wave');
    }
  },
};

//--------------------------------------------------------------------------
function c89(bytes) {
  var s = '';
  var g = '';
  for (var i = 0; i < bytes.length; i++) g += '%' + bytes[i].toString(16);
  s += g;
  return decodeURIComponent(g);
}
//-------------------------------table init------------------------------------------
jQuery.fn.tableAdaptor = function (npage) {
  var params = getConfig(this);
  if (params == '') {
    log('error:未配置table 的 config-option属性');
    return;
  }

  // 获取表格列信息
  var getContentVal = function getContent(j, obj) {
    var val = '<tr tag="' + j + '" value="' + obj.id + '">';
    for (var i = 0; i < params.columns.length; i++) {
      var flag = params.columns[i].click_callback != undefined;
      val +=
        '<td ' +
        (flag
          ? 'onclick="' + params.columns[i].click_callback + '(this)"'
          : '') +
        "class='" +
        gdv(params.columns[i].style_class, '') +
        "'" +
        ' >' +
        getMultiValue(i, j, obj) +
        '</td>';
    }
    val += '</tr>';
    return val;
  };

  String.prototype.lgformat = function () {
    var args = arguments;
    return this.replace(/\{([\w-*\.*]+)\}/g, function (m, i) {
      s = i.split('.');
      var r = args[0][s[0]];
      for (var j = 1; j < s.length; j++) {
        r = r[s[j]];
      }
      return getVal(r, '');
    });
  };

  var getMultiValue = function getMultiValueFunc(i, j, obj) {
    var val = '';
    var reg = /\{([\w-*\.*]+)\}/g;
    if (reg.test(params.columns[i].value)) {
      return params.columns[i].value.lgformat(obj);
    } else {
      val = getVal(
        eval(
          getTypeValue(
            params.columns[i].value,
            params.columns[i].type,
            j,
            params.columns[i].name,
            params.columns[i].timeformat,
            params.columns[i]
          )
        ),
        getVal(params.columns[i].default_value, '')
      );
    }
    return val;
  };

  var getImgValue = function getImgValueFunc(img_type) {
    return imgUrl + img_type;
  };

  var getTypeValue = function getTypeValueFunc(
    val,
    type,
    i,
    name,
    timeformat,
    obj
  ) {
    if (type == 'fix') {
      return "'" + val + "'";
    } else if (type == 'category') {
      if (!validater.empty(obj.style)) {
        if (typeof obj.style == 'object') {
          if (!validater.empty(obj.style[aobj.data('obj_loygra')[val]])) {
            if (aobj.data('obj_loygra')['data'] != null) {
              return (
                "'<span style=" +
                obj.style[aobj.data('obj_loygra')[val]].replace(/,/g, ':') +
                '>' +
                aobj.data('obj_loygra')['data'][val] +
                "</span>'"
              );
            }
          }
        } else {
          if (aobj.data('obj_loygra')['data'] != null) {
            return (
              "'<span style=" +
              obj.style.replace(/,/g, ':') +
              '>' +
              aobj.data('obj_loygra')['data'][val] +
              "</span>'"
            );
          }
        }
      }
      if (aobj.data('obj_loygra')['data'] != null) {
        return '"' + aobj.data('obj_loygra')['data'][val] + '"';
      } else {
        return '""';
      }
    } else if (type == 'seq') {
      return i + 1 + aobj.data('obj_loygra_config');
    } else if (type == 'img') {
      return (
        '"<img title=\'' +
        getVal(name) +
        "' src='" +
        getImgValue(val) +
        '\'  />"'
      );
    } else if (type == 'time') {
      return (
        'timeStamp2String(' +
        aobj.data('obj_loygra')[obj.value] +
        ',"' +
        getVal(timeformat, '') +
        '")'
      );
    } else if (type == 'self') {
      if (!validater.empty(val)) {
        var callBack_func = eval('(' + obj.value_callback + ')');
        return (
          '"' +
          callBack_func(
            aobj.data('obj_loygra')[val],
            aobj.data('obj_loygra'),
            i
          ) +
          '"'
        );
      }
      var callBack_func2 = eval('(' + obj.value_callback + ')');
      return '"' + callBack_func2(aobj.data('obj_loygra'), i) + '"';
    } else if (type == 'cb') {
      return "'" + '<input type="checkbox">' + "'";
    } else {
      if (!validater.empty(obj.limit)) {
        return (
          '\'<span class="limiter" tag="' +
          aobj.data('obj_loygra')[val] +
          '">' +
          disvalue(aobj.data('obj_loygra')[val], obj.limit) +
          "</span>'"
        );
      } else {
        if (!validater.empty(obj.style)) {
          if (typeof obj.style == 'object') {
            if (validater.empty(obj.style[aobj.data('obj_loygra')[val]])) {
              return "'<span>" + aobj.data('obj_loygra')[val] + "</span>'";
            } else {
              return (
                "'<span style=" +
                obj.style[aobj.data('obj_loygra')[val]].replace(/,/g, ':') +
                '>' +
                aobj.data('obj_loygra')[val] +
                "</span>'"
              );
            }
          } else {
            return (
              "'<span style=" +
              obj.style.replace(/,/g, ':') +
              '>' +
              aobj.data('obj_loygra')[val] +
              "</span>'"
            );
          }
        } else {
          return "'" + aobj.data('obj_loygra')[val] + "'";
        }
      }
    }
  };

  var getajaxDateVal = function getAjaxData(num, paramData, fresh) {
    if (localUrl == null || localUrl == '') {
      console.log('请先配置 localUrl的值');
      return;
    }

    var t1;
    if (params.wait != null && !params.wait) {
    } else {
      t1 = operate_wait('Please wait...', 10000, 0.01);
    }
    var sparam = '';
    if (params.url.indexOf('pageSize') > -1) {
      sparam = params.url + '&paged=' + num;
    } else {
      sparam = params.url + '?paged=' + num;
    }
    commonAjax(
      'POST',
      localUrl + sparam,
      paramData,
      function (data) {
        obj.data('searchflag', false);
        $('#' + obj.data('tbody-id')).empty();
        if (data.status == status_code.OK) {
          if (validater.empty(data.data)) {
            if (layer != null) {
              layer.close(t1);
            }
            return;
          }
          obj.data(
            'obj_loygra_config',
            data.data.pageSize * (data.data.paged - 1)
          );
          obj.data('cache', data.data.data);
          for (var i = 0; i < data.data.data.length; i++) {
            obj.data('obj_loygra', data.data.data[i]);
            $('#' + obj.data('tbody-id')).append(
              getContentVal(i, data.data.data[i])
            );
          }

          if (fresh) {
            if (params.pager != null) {
              init_papination(
                '#' + params.pager,
                num,
                data.data.totalPage,
                function (n, m) {
                  getajaxDateVal(n, obj.data('params'), false);
                }
              );
            } else {
              kkpagerInit(
                num,
                data.data.totalPage,
                data.data.totalCount,
                function (n) {
                  getajaxDateVal(n, obj.data('params'), false);
                }
              );
            }
          }
          // 判断是否只有1页，如果是，则隐藏分页
          if (data.data.totalPage <= 1 && npage != -1) {
            $('#kkpager').hide();
          }
          if (!validater.empty(table_operate_init)) {
            table_operate_init();
          }
          if (params.success != null) {
            eval('(' + params.success + '(data)' + ')');
          }
        } else if (
          data.status == status_code.NO_DATA ||
          $('#' + obj.data('tbody-id')).html() == ''
        ) {
          $('#' + obj.data('tbody-id')).append(
            "<div style='margin-left: 46%;position: absolute;margin-top: 15px;color: #aaa;' ><i>No further data available</i></div>"
          );
        } else {
          if (params.error != null) {
            eval('(' + params.error + '(data)' + ')');
          }
        }
        if (layer != null) {
          layer.close(t1);
        }
      },
      function () {
        obj.data('searchflag', false);
      }
    );
  };
  var obj = this;
  var aobj = this;
  // layui-table
  var dom =
    '<table class="layui-table ' +
    getVal(params.style_class) +
    '"><thead class="lpro-thead" >\
			<tr>';

  for (var i = 0; i < params.columns.length; i++) {
    var className = 'cb_click' + getRandom(10) + i;
    var cbflag = params.columns[i].type == 'cb';
    if (cbflag) {
      params.columns[i].style_class = className; // + " " + getVal(params.columns[i].style_class)
      this.undelegate('.' + className + ' input', 'click');
      this.delegate('.' + className + ' input', 'click', function () {
        if ($(this).parent()[0].tagName == 'TH') {
          if ($(this).is(':checked')) {
            $('.' + $(this).parent().attr('class') + ' input').attr(
              'checked',
              true
            );
          } else {
            $('.' + $(this).parent().attr('class') + ' input').attr(
              'checked',
              false
            );
          }
        } else if ($(this).parent()[0].tagName == 'TD') {
          if (
            $(
              'td.' +
                $(this).parent().attr('class') +
                " input[type='checkbox']:checked"
            ).length ==
            $('td.' + $(this).parent().attr('class') + ' input').length
          ) {
            $('th.' + $(this).parent().attr('class') + ' input').attr(
              'checked',
              true
            );
          } else {
            $('th.' + $(this).parent().attr('class') + ' input').attr(
              'checked',
              false
            );
          }
        }
      });
    }
    dom +=
      '<th ' +
      (cbflag ? "class='" + className + "'" : '') +
      "  style='width:" +
      getVal(params.columns[i].width, '') +
      "' >" +
      (params.columns[i].type != 'cb'
        ? params.columns[i].name
        : "<input type='checkbox' >") +
      '</th>';
  }
  var tbody_id = 'container' + Math.round(Math.random() * 10000000);
  dom +=
    '</tr>\
			</thead>\
			<tbody class="tbody" id="' +
    tbody_id +
    '">\
			</tbody>\
		</table>';

  if (params.pager != null) {
    params.pagerStyle = 'pager-' + Math.round(Math.random() * 10000000);
    dom +=
      '<div style="text-align: right;padding:5px"><div id="' +
      params.pagerStyle +
      '"></div></div>';
  } else {
    dom +=
      '<div class="page-container" style="height: 40px;" >\
			<div id="kkpager"></div>\
			</div>';
  }
  if (npage != null && npage != -1) {
    getajaxDateVal(npage, obj.data('params'), false);
    return;
  }
  obj.empty();
  obj.append(dom);
  obj.data('tbody-id', tbody_id);
  if (!(obj.data('params') != null && obj.data('params') != '')) {
    obj.data('params', objecter(gdv(params.param, {}), '$'));
  }

  getajaxDateVal(1, obj.data('params'), true);
};

function get_table_cb(selector, property, seq) {
  var array = [];
  var td_input = $(
    'td.' +
      $(selector + ' th')
        .eq(gdv(seq, 0))
        .attr('class')
  );
  for (var i = 0; i < td_input.length; i++) {
    if (td_input.eq(i).children().eq(0).is(':checked')) {
      if (!validater.empty(property)) {
        array.push(
          $(selector).data('cache')[td_input.eq(i).parent().attr('tag')][
            property
          ]
        );
      } else {
        array.push(td_input.eq(i).parent().attr('tag'));
      }
    }
  }
  return array;
}

// 外部调用表格(带分页)
function out_init_table(selector, param) {
  if (!validater.empty(param)) {
    $(selector).data('params', param);
  }
  $(selector).tableAdaptor();
}

//-----------------------------------------------------------------------------------------------------------------
//--------------------------------------------pager-----------------------------------------------------------------
/**
 *
 * @param currentPage
 * @param totalPage
 * @param totalCounts
 * @param func  ,不需要回调修改页面的函数
 * @returns
 */
function kkpagerInit(currentPage, totalPages, totalCounts, func) {
  var sum = totalCounts; //总数据条数后台返回数据
  var totalPage = totalPages; //总页数总数据条数/每页显示数 向上取整
  var current = 1; //当前页数      后台返回数据
  if (current == 0 || currentPage == undefined) {
    current = 1;
  }
  //初始化函数
  kkpager.generPageHtml(
    {
      pno: current, //当前页数
      total: totalPage, //总页数
      totalRecords: sum, //总数据条数
      mode: 'click', //这里设置为click模式
      lang: {
        prePageText: 'Previous',
        nextPageText: 'Next page',
        totalPageBeforeText: ' ',
        totalPageAfterText: ' pages in total,' + totalCounts + ' article , ',
        totalRecordsAfterText: 'Piece of data',
        gopageBeforeText: ' Go to page',
        gopageButtonOkText: 'confirm',
        gopageAfterText: '________',
        buttonTipBeforeText: 'The',
        buttonTipAfterText: 'page',
      },
      click: function (n) {
        func(n);
        this.selectPage(n); //手动条用selectPage进行页码选中切换
      },
      //设置href链接地址,默认#
      getHref: function (n) {
        return 'javascript:;;';
      },
    },
    true
  );
}

//------------------------------------------------------------------------------------------------------
//-------------------------------------jquery pagination------------------------------------------------
function init_papination(selector, current, total, func) {
  //	$(selector).whjPaging({
  //        pageSizeOpt: [
  //                      {'value': 5, 'text': '5条/页', 'selected': true},
  //                      {'value': 10, 'text': '10条/页'},
  //                      {'value': 15, 'text': '15条/页'},
  //                      {'value': 20, 'text': '20条/页'}
  //                  ],
  //                  totalPage: 19,
  //                  showPageNum: 5,
  //                  firstPage: '首页',
  //                  previousPage: '上一页',
  //                  nextPage: '下一页',
  //                  lastPage: '尾页',
  //                  skip: '跳至',
  //                  confirm: '确认',
  //                  refresh: '刷新',
  //                  totalPageText: '共{}页',
  //                  isShowFL: true,
  //                  isShowPageSizeOpt: false,
  //                  isShowSkip: true,
  //                  isShowRefresh: false,
  //                  isShowTotalPage: true,
  //                  isResetPage: false,
  //                  callBack: function (currPage, pageSize) {
  //                      func(currPage,pageSize);
  //                  }
  //              });
  //	$(selector).whjPaging("setPage", current, total);
}
//-------------------------------------------------------------------------------
//-----------------------------other detail_get_restall--------------------------------------------------
function detail_get_restall(selector, _config) {
  var config = _config;
  var childs = $(selector).find('[type-name]');
  getAjax(
    localUrl + config.url,
    function (data) {
      if (data.status == status_code.OK) {
        for (var j = 0; j < childs.length; j++) {
          if (childs.eq(j).attr('type-value') == 'h') {
            childs.eq(j).html(data.data[childs.eq(j).attr('type-name')]);
          } else {
            childs.eq(j).val(data.data[childs.eq(j).attr('type-name')]);
          }
        }
      }
      if (config.success != null) {
        eval('(' + config.success + '(data)' + ')');
      }
    },
    function () {
      if (config.error != null) {
        eval('(' + config.error + '()' + ')');
      }
    }
  );
}

//------------------------------------------------------------------------------------------
//------------------------文件上传------------------------------------
/**
 * @Func 文件上傳功能，目前只支持單個
 * @param imgUrl domain
 * @param user_id 用戶id
 * @param func 成功之後的回調
 * @Param id 文件选择id
 */
function UploadInit(
  imgFindUrl,
  userInfo,
  func,
  id,
  domId,
  thumbnailWidth,
  thumbnailHeight,
  accept,
  acceptconfig
) {
  var $ = jQuery,
    state = 'pending',
    uploader;
  // 增加类型修改，可以传入类型
  if (accept == undefined) {
    acceptconfig = '';
  } else {
    acceptconfig = getVal(acceptconfig, {
      // 默认值兼容之前
      title: 'Images',
      extensions: 'gif,jpg,jpeg,bmp,png,pdf',
      mimeTypes: 'image/jpg,image/jpeg,image/png',
    });
  }

  uploader = WebUploader.create({
    // 自动上传
    auto: true,
    // 不压缩image
    resize: false,
    //不压缩图片
    compress: false,
    // swf文件路径
    swf: imgUrl + '/lib/webUploader/Uploader.swf',
    // 文件接收服务端。
    server: imgFindUrl,
    // 选择文件的按钮。可选。
    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
    pick: '#' + id,
    duplicate: true,
    fileSingleSizeLimit: 5 * 1024 * 1024,
    // 只允许选择文件，可选。
    accept: acceptconfig,
  });

  uploader.on('error', function (type) {
    if (type == 'Q_TYPE_DENIED') {
      if (typeof layer != 'undefined') {
        showTip('Please upload the correct file format');
      } else {
        alert('Please upload the correct file format');
      }
    } else if (type == 'F_EXCEED_SIZE') {
      if (typeof layer != 'undefined') {
        showTip('The file size cannot exceed 5M');
      } else {
        alert('The file size cannot exceed 5M');
      }
    }
  });
  // 当有文件添加进来的时候
  uploader.on('fileQueued', function (file) {
    $('#' + domId).css('width', '0%');
    $('#' + domId).attr('ids', '');
    $('#' + domId).css('display', 'inherit');
    uploader.options.formData = gdv(userInfo, {});
    uploader.makeThumb(
      file,
      function (error, src) {
        $('#back_' + domId).css('background', 'url(' + src + ')');
      },
      thumbnailWidth,
      thumbnailHeight
    );
  });
  // 文件上传过程中创建进度条实时显示。
  uploader.on('uploadProgress', function (file, percentage) {
    $('#all_' + domId).text(parseInt(percentage * 100) + '%');
    $('#' + domId).css('width', parseInt(100 - percentage * 100) + '%');
  });
  uploader.on('uploadSuccess', func);
  uploader.on('uploadError', function (file) {
    console.log('文件上传出错');
  });
  uploader.on('uploadComplete', function (file) {});
  uploader.on('all', function (type) {});
}
//------------------------------------------------------------------------------------------
//------------------------弹出层------------------------------------
/**
 * @自定义弹窗
 * @Param title 标题 , selector 选择器
 * @Return layer
 */
function openWindow(titleName, selector, width, skinColor) {
  if (width == undefined || width == '') {
    width = 'auto';
  }
  if (skinColor == undefined || skinColor == '') {
    skinColor = 'loygra-layer-skin';
  }
  var index = layer.open({
    title: titleName,
    type: 1,
    area: width,
    skin: skinColor,
    shadeClose: true,
    content: $(selector),
  });
  return index;
}

/**
 * 通过ajax请求服务器数据，生成select
 */
function init_select(object, selector) {
  commonAjax(
    gdv(object.method, 'POST'),
    localUrl + object.url,
    object.method == 'GET' ? '' : objecter(gdv(object.data, {}), '$'),
    function (data) {
      gdv(selector, $(object.selector)).empty();
      if (data.status == status_code.OK) {
        var dataTemp;
        if (validater.empty(data.data)) {
          return;
        }
        if (object.type == null || object.type == 'page') {
          dataTemp = data.data.data;
        } else {
          dataTemp = data.data;
        }
        if (!validater.empty(object.init_value)) {
          gdv(selector, $(object.selector)).append(
            "<option value='' >" + object.init_value + '</option>'
          );
        }
        for (var i = 0; i < dataTemp.length; i++) {
          var tempOption = '';
          var a = object.value.split(',');
          if (a.length == 2) {
            tempOption =
              '<option ' +
              (dataTemp[i][gdv(object.key, 'key')] == object.default_value
                ? 'selected'
                : '') +
              "  value='" +
              dataTemp[i][gdv(object.key, 'key')] +
              "'>" +
              dataTemp[i][gdv(a[0], 'value')] +
              ' / ' +
              dataTemp[i][gdv(a[1], 'value')] +
              '</option>';
          } else if (a.length == 1) {
            tempOption =
              '<option ' +
              (dataTemp[i][gdv(object.key, 'key')] == object.default_value
                ? 'selected'
                : '') +
              "  value='" +
              dataTemp[i][gdv(object.key, 'key')] +
              "'>" +
              dataTemp[i][gdv(object.value, 'value')] +
              '</option>';
          }
          gdv(selector, $(object.selector)).append(tempOption);
        }
        if (!validater.empty(object.success)) {
          eval('(' + object.success + '()' + ')');
        }
      } else {
        if (!validater.empty(object.init_value)) {
          gdv(selector, $(object.selector)).append(
            "<option value='' >" + object.init_value + '</option>'
          );
        } else {
          gdv(selector, $(object.selector)).append(
            "<option value='' >Please select</option>"
          );
        }
      }
    }
  );
}

/**
 *
 * @param object
 * {
 * 		method:'POST',
 * 		url:'url',
 * 		param:{},
 * 		data:{ treeNode属性
 * 				id:'id',
 * 				pId:'pId',
 * 				name:'name',
 * 				t:'r'
 * 			 },
 * 		onClick:回调方法
 * 		settting：配置  可不填
 * 		selector:selector  // 容器div
 * }
 * @returns
 */
function ajaxInitTree(object) {
  commonAjax(
    gdv(object.method, 'POST'),
    localUrl + object.url,
    gdv(object.param, {}),
    function (data) {
      $(object.selector).empty();
      if (data.status == status_code.OK) {
        var dataTemp = data.data;
        var treeData = [];
        for (var i = 0; i < dataTemp.length; i++) {
          var tmpdata = {};
          tmpdata['id'] = dataTemp[i][object.data.id];
          tmpdata['pId'] = dataTemp[i][object.data.pId];
          tmpdata['name'] = dataTemp[i][object.data.name];
          tmpdata['t'] = dataTemp[i][object.data.t];
          tmpdata['open'] = gdv(object.isOpen, 'false');
          treeData[i] = tmpdata;
        }
        object.nodes = treeData;
        treeInit(object);
      }
    }
  );
}

/**
 * 树型
 * @param object
 * @colums	selector div容器
 * @colums	nodes	数据
 * @colums	onClick	func 点击回调
 * @returns
 */
function treeInit(object) {
  $(object.selector).empty();
  var treeSelector = 'tree-' + getRandom(5);
  $(object.selector).append(
    '<ul id="' + treeSelector + '" class="ztree"></ul>'
  );
  $('#' + treeSelector).data('selector', treeSelector);
  var setting = {
    data: {
      simpleData: {
        enable: true,
      },
    },
    callback: {},
  };
  if (!validater.empty(object.onClick)) {
    setting.callback.onClick = object.onClick;
  }
  $.fn.zTree.init(
    $('#' + treeSelector),
    gdv(object.setting, setting),
    object.nodes
  );
  if (object.success != null) {
    object.success();
  }
}

/**
 * 返回treeObj
 * 其他API：http://www.treejs.cn/v3/api.php
 * @param selecor
 * @returns treeObj
 */
function getParentTree(selecor) {
  return $.fn.zTree.getZTreeObj($(selecor).children().eq(0).data('selector'));
}
/**
 * 浏览器类型判断
 * @param osName
 * @returns bool Or (osName when isName is null)
 */
function getOs(osName) {
  var os_name = '';
  var userAgent = navigator.userAgent;
  var isOpera = userAgent.indexOf('Opera') > -1;
  //判断是否Opera浏览器
  if (isOpera) {
    os_name = 'Opera';
  }
  //判断是否Firefox浏览器
  if (userAgent.indexOf('Firefox') > -1) {
    os_name = 'FF';
  }
  //判断是否chorme浏览器
  if (userAgent.indexOf('Chrome') > -1) {
    os_name = 'Chrome';
  }
  //判断是否Safari浏览器
  if (userAgent.indexOf('Safari') > -1) {
    os_name = 'Safari';
  }
  //判断是否IE浏览器
  if (
    userAgent.indexOf('compatible') > -1 &&
    userAgent.indexOf('MSIE') > -1 &&
    !isOpera
  ) {
    os_name = 'IE';
  }
  //判断是否Edge浏览器
  if (userAgent.indexOf('Trident') > -1) {
    os_name = 'Edge';
  }
  if (osName != null) {
    return osName == os_name;
  } else {
    return os_name;
  }
}

/**
 * 更改iframe url
 */
function changeIframeUrl(url, selector) {
  if (validater.empty(url)) {
    return;
  }
  if (!validater.empty(typeof layer)) {
    layer.load(2);
    setTimeout(function () {
      layer.closeAll();
    }, 500);
  }
  if (url.indexOf(localUrl) > -1) {
    $(gdv(selector, '#myiframe')).attr('src', url);
  } else {
    $(gdv(selector, '#myiframe')).attr('src', localUrl + url);
  }
}

/**
 * 跳转URL
 * @param url
 * @param timeout
 * @param tip_info
 * @returns
 */
function forwardUrl(url, timeout, tip_info) {
  if (!validater.empty(typeof layer) && validater.empty(tip_info)) {
    layer.load(2);
    setTimeout(function () {
      layer.closeAll();
    }, 500);
  }
  if (validater.empty(timeout)) {
    location.href = localUrl + url;
  } else {
    if (validater.empty(tip_info)) {
      setTimeout(function () {
        location.href = localUrl + url;
      }, timeout);
    } else {
      tip(tip_info);
      setTimeout(function () {
        location.href = localUrl + url;
      }, timeout);
    }
  }
}

function GetQueryString(name) {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
  var r = window.location.search.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
}

/**
 * 去除没有匹配带的数值
 * @param s
 * @returns
 */
function removeformat(s) {
  return s.replace(/\{([\w-*\.*]+)\}/g, function (m, i) {
    return '';
  });
}

String.prototype.format = function () {
  if (arguments.length == 0) return this;
  var param = arguments[0];
  var s = this;
  if (typeof param == 'object') {
    for (var key in param) {
      if (key == 'data') {
        for (var subKey in param.data) {
          s = s.replace(
            new RegExp('\\{' + key + '.' + subKey + '\\}', 'g'),
            param.data[subKey]
          );
        }
      } else {
        s = s.replace(new RegExp('\\{' + key + '\\}', 'g'), param[key]);
      }
    }
    // 这边再对特殊数值进行处理
    // 处理方括号的data数值
    s = s.replace(/\[([\w-*\.*]+)\]/g, function (m, i) {
      if (i.indexOf('.') > -1) {
        var str = i.split('.');
        return timeStamp2String(param[str[0]], str[1]);
      } else {
        return timeStamp2String(param[i]);
      }
    });

    return removeformat(s);
  } else {
    for (var i = 0; i < arguments.length; i++)
      s = s.replace(new RegExp('\\{' + i + '\\}', 'g'), arguments[i]);
    return s;
  }
};

function tom(flg, val, val2) {
  return flg ? val : val2;
}

function inIframe() {
  if (self != top) {
    parent.location.reload();
  }
}

function encodeUtf8(text) {
  const code = encodeURIComponent(text);
  const bytes = [];
  for (var i = 0; i < code.length; i++) {
    const c = code.charAt(i);
    if (c === '%') {
      const hex = code.charAt(i + 1) + code.charAt(i + 2);
      const hexVal = parseInt(hex, 16);
      bytes.push(hexVal);
      i += 2;
    } else bytes.push(c.charCodeAt(0));
  }
  return bytes;
}

function decodeUtf8(bytes) {
  var encoded = '';
  for (var i = 0; i < bytes.length; i++) {
    encoded += '%' + bytes[i].toString(16);
  }
  return decodeURIComponent(encoded);
}

// 延时等待效果
function delayOperate(time, func) {
  layer.load(2);
  setTimeout(function () {
    closeAll();
    func();
  }, gdv(time, 500));
}

// js 时间比较操作
var DateUtil = {
  compare: function (startDate, endDate, time) {
    if (typeof startDate == 'string') {
      startDate = new Date(startDate);
      endDate = new Date(endDate);
    }
    if (endDate.getTime() - startDate.getTime() < time) {
      return true;
    } else {
      return false;
    }
  },
  addDate: function (dates, days) {
    var d = dates;
    d.setDate(d.getDate() + days);
    return d;
  },
};
function isOK(data) {
  if (data.status == status_code.OK) {
    return true;
  } else {
    return false;
  }
}

function IsPC() {
  var userAgentInfo = navigator.userAgent;
  var Agents = [
    'Android',
    'iPhone',
    'SymbianOS',
    'Windows Phone',
    'iPad',
    'iPod',
  ];
  var flag = true;
  for (var v = 0; v < Agents.length; v++) {
    if (userAgentInfo.indexOf(Agents[v]) > 0) {
      flag = false;
      break;
    }
  }
  return flag;
}

function disvalue(val, length) {
  if (val != null) {
    if (length >= val.length) {
      return val;
    } else {
      return val.substring(0, length) + '..';
    }
  } else {
    return '';
  }
}

function lcomfirm(title, successfunc, errorfunc, buttonName1, buttonName2) {
  layer.confirm(
    gdv(title, 'Message'),
    {
      btn: [gdv(buttonName1, 'OK'), gdv(buttonName2, 'Cancel')],
    },
    function () {
      if (!validater.empty(successfunc)) {
        successfunc();
      }
    },
    function () {
      if (!validater.empty(errorfunc)) {
        errorfunc();
      }
    }
  );
}

function convertControl(value, measure, device_status) {
  if (validater.empty(measure)) {
    return '';
  }
  var str = measure.split(',');
  if (str.length != 2) {
    tip('The sensor unit is incorrectly set');
    return '';
  }
  for (var i = 0; i < str.length; i++) {
    if (str[i].indexOf(device_status) > -1) {
      var subStr = str[i].split(':');
      if (subStr.length != 2) {
        tip('The sensor unit is incorrectly set');
        return '';
      } else {
        if (subStr[0] == value) {
          // 满足
          if (i == 0) {
            return str[1].split(':')[0];
          } else {
            return str[0].split(':')[0];
          }
        } else {
          return '';
        }
      }
    }
  }
}

function randomWord(randomFlag, min, max) {
  var str = '';
  var range = min;
  var arr = [
    '0',
    '1',
    '2',
    '3',
    '4',
    '5',
    '6',
    '7',
    '8',
    '9',
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
    'g',
    'h',
    'i',
    'j',
    'k',
    'l',
    'm',
    'n',
    'o',
    'p',
    'q',
    'r',
    's',
    't',
    'u',
    'v',
    'w',
    'x',
    'y',
    'z',
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'G',
    'H',
    'I',
    'J',
    'K',
    'L',
    'M',
    'N',
    'O',
    'P',
    'Q',
    'R',
    'S',
    'T',
    'U',
    'V',
    'W',
    'X',
    'Y',
    'Z',
  ];

  if (randomFlag) {
    range = Math.round(Math.random() * (max - min)) + min; // 任意长度
  }
  for (var i = 0; i < range; i++) {
    pos = Math.round(Math.random() * (arr.length - 1));
    str += arr[pos];
  }
  return str;
}
// str to json a:b,c:d
function strToJson(str) {
  var data = {};
  var s = str.split(',');
  for (var i = 0; i < s.length; i++) {
    var j = s[i].split(':');
    data[j[0]] = j[1];
  }
  return data;
}
